USE [CTEM-DB-v1]
GO

/****** Object:  StoredProcedure [dbo].[Employee_UpdateSalary]    Script Date: 02/10/2012 11:22:35 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		TienDH
-- Create date: 12/05/2011
-- Description:	Get full employee's information
-- =============================================
CREATE PROCEDURE [dbo].[Employee_UpdateSalary]	
	@SalaryID		BIGINT,
	@EmployeeID		BIGINT,
	@Month			VARCHAR(6),
	@Salary			BIGINT,
	@SalaryPC		BIGINT,
	@TotalAllowance	BIGINT,	
	@DebtPay		BIGINT,
	@Debt1			BIGINT,
	@Debt2			BIGINT,
	@TotalAdvanceSalary BIGINT,
	@ActualIncome	BIGINT,
	@GenDebt		BIGINT,
	@DateReceive	DATETIME,
	@isPay			BIT
AS
BEGIN
	DECLARE @date		DATETIME,
			@debtpayold	BIGINT,
			@gendebtold BIGINT
	SET		@date = GETDATE()
	
	SELECT	@debtpayold = DebtPay, @gendebtold = GenerateDebt
	FROM	EmployeeSalary
	WHERE	EmployeeSalaryID = @SalaryID
	
	UPDATE	EmployeeSalary
	SET		EmployeeID = @EmployeeID,
			[Month] = @Month,
			Salary = @Salary,
			SalaryPC = @SalaryPC,
			TotalAllowance = @TotalAllowance,
			DebtPay = @DebtPay,
			Debt1 = @Debt1,
			Debt2 = @Debt2,
			TotalAdvanceSalary = @TotalAdvanceSalary,
			GenerateDebt = @GenDebt,
			ActualIncome = @ActualIncome,
			isPay = @isPay,			
			LastUpdate = @date
	WHERE	EmployeeSalaryID = @SalaryID
	
	UPDATE	Employee
	SET		TotalDebt = TotalDebt - @gendebtold + @GenDebt + @debtpayold - @DebtPay
	WHERE	EmployeeID = @EmployeeID
END

GO

